package com.hamster.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hamster.crm.mapper.AffiliatesProgramConfigMapper;
import com.hamster.crm.pojo.AffiliatesProgramConfig;
import com.hamster.crm.service.AffiliatesProgramConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 【后台】项目加盟设置  service
 * @author Tarry
 * @create 2019/12/23 14:52
 */
@Service
public class AffiliatesProgramConfigServiceImpl implements AffiliatesProgramConfigService {
    @Autowired
    private AffiliatesProgramConfigMapper affiliatesProgramConfigMapper;

    /**
     * 获取项目加盟设置列表
     * @param department 0 普通项目加盟 1服务部项目加盟
     * @return List<AffiliatesProgramConfig> 项目加盟设置列表
     */
    @Override
    public List<AffiliatesProgramConfig> list(String department) {
        QueryWrapper<AffiliatesProgramConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del","0").orderByDesc("id"); //查询状态正常的项目加盟设置
        queryWrapper.eq("department",department); //指定 查询哪个部门的项目加盟设置

        return affiliatesProgramConfigMapper.selectList(queryWrapper);
    }

    /**
     * 添加1条 项目加盟设置
     * @param affiliatesProgramConfig
     */
    @Override
    public void insert(AffiliatesProgramConfig affiliatesProgramConfig) {
        affiliatesProgramConfig.setDel("0");
        affiliatesProgramConfig.setInputTime(new Date());
        affiliatesProgramConfig.setInputUser("功能的待完善");
        affiliatesProgramConfigMapper.insert(affiliatesProgramConfig);
    }

    /**
     * 根据id删除项目加盟设置
     * @param ids
     */
    @Transactional
    @Override
    public void delete(List<String> ids) {
        for (String id : ids) {
            affiliatesProgramConfigMapper.deleteTag(id);
        }
    }

    /**
     * 根据id 获取指定的项目加盟设置
     * @param id
     * @return
     */
    @Override
    public AffiliatesProgramConfig get(String id) {
        return affiliatesProgramConfigMapper.selectById(id);
    }

    /**
     * 修改项目加盟设置 内容
     * @param affiliatesProgramConfig
     */
    @Override
    public void update(AffiliatesProgramConfig affiliatesProgramConfig) {

        affiliatesProgramConfigMapper.updateById(affiliatesProgramConfig);
    }
}
